//
//  YDMessageTableViewCell.m
//  IngCard
//
//  Created by kf on 2017/8/10.
//  Copyright © 2017年 IngDan. All rights reserved.
//

#import "YDSystemMessageTableViewCell.h"

@implementation YDSystemMessageCellDataSource

-(Class) viewClass
{
    return [YDSystemMessageTableViewCell class];
}

@end

@interface YDSystemMessageTableViewCell()
@property(nonatomic, strong) UIImageView *imageTitleView;
@property(nonatomic, strong) UILabel *titleLabel;
@property(nonatomic, strong) UILabel *subTitleLabel;

@property(nonatomic, strong) UIView *separatorLine;
@end

@implementation YDSystemMessageTableViewCell

+(CGFloat)viewHeight:(YDSystemMessageCellDataSource *) dataSource
{
    return 72;
}


- (void) initSubviews
{
    [super initSubviews];
    
    [self.contentView addSubview:self.imageTitleView];
    [self.imageTitleView makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(30);
        make.top.equalTo(self.contentView).offset(10);
        make.width.equalTo(52);
        make.height.equalTo(52);
    }];
    
    [self.contentView addSubview:self.titleLabel];
    [self.titleLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(109);
        make.top.equalTo(self.contentView).offset(13);
        make.right.equalTo(self.contentView).offset(-20);
    }];
    
    [self.contentView addSubview:self.subTitleLabel];
    [self.subTitleLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleLabel);
        make.top.equalTo(self.titleLabel.mas_bottom).offset(3);
        make.right.equalTo(self.contentView).offset(-20);
    }];

    [self.contentView addSubview:self.separatorLine];
    [self.separatorLine makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(30);
        make.right.equalTo(self.contentView).offset(-1);
        make.bottom.equalTo(self.contentView);
        make.height.equalTo(1);
    }];
}

-(void) onViewModelChanged
{
    YDSystemMessageCellDataSource *dataSource = (YDSystemMessageCellDataSource *)self.dataSource;
    if (dataSource)
    {
        self.titleLabel.text = dataSource.title;
        self.subTitleLabel.text = dataSource.subTitle;
        self.imageTitleView.image = dataSource.titleImage;
    }
}


#pragma mark - lazy loading

- (UILabel *) titleLabel
{
    if (!_titleLabel)
    {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.text = @"姓名";
        _titleLabel.textAlignment = NSTextAlignmentLeft;
        _titleLabel.font = UIFontMake(17);
        _titleLabel.textColor = UIColorMake(0, 0, 0);
        [_titleLabel sizeToFit];
    }
    return _titleLabel;
}

- (UILabel *) subTitleLabel
{
    if (!_subTitleLabel)
    {
        _subTitleLabel = [[UILabel alloc] init];
        _subTitleLabel.text = @"姓名";
        _subTitleLabel.textAlignment = NSTextAlignmentLeft;
        _subTitleLabel.font = UIFontMake(14);
        _subTitleLabel.textColor = UIColorMake(106, 106, 106);
    }
    return _subTitleLabel;
}


- (UIImageView *) imageTitleView
{
    if (!_imageTitleView)
    {
        _imageTitleView = [UIImageView new];
        _imageTitleView.image = TableViewCellDisclosureIndicatorImage;
        _imageTitleView.contentMode = UIViewContentModeCenter;
    }
    return _imageTitleView;
}

-(UIView *)separatorLine
{
    if (!_separatorLine)
    {
        _separatorLine = [[UIView alloc] init];
        _separatorLine.backgroundColor = UIColorMake(200, 199, 204);
    }
    return _separatorLine;
}
@end
